#include <stdio.h>
#include <stdlib.h>
#include "linkstack.h"
LinkStack Create(){
    LinkStack lstack=(LinkStack)malloc(sizeof(struct Stack));
    if(lstack!=null){
    lstack->top=NULL;
    lstack->size=0;  
    }
return lstack;
}    

int IsEmpty(LinkStack stack){
 if(stack->top==NULL||stack->size==0){
  return 1;
  }
  return 0;
 }
 int getSize(LinkStack stack){
  if(!IsEmpty(stack)){
    return(stack->size);
  }
  return 0;
}
int Push(LinkStack stack,char val){
  pNode node=(pNode)malloc(sizeof(struct Node));
  if(node!=null){
  node->data=val;
  node->next=getTop(lstack);
  lstack->top=node;
  lstack->size++;
  }
 return 1; 
}
 pNode getTop(LinkStack lstack){
  if(!IsEmpty(lstack)){
    return lstack->top;
    } 
    return NULL;
  }
pNode Pop(LinkStack lstack){
  if(IsEmpty(lstack)){
      return NULL;
    }
  pNode node=lstack->top;
  lstack->top=lstack->top->next;
  lstack->size--;
  return node;
}
 void Destory(LinkStack lstack){
    if(IsEmpty(lstack)){
        free(lstack);
        printf("栈以为空，无需清理\n");
        return;
    }
//如果栈不为空，需要把栈中的结点都释放
do{
        pNode pTmp;
        pTmp=Pop(lstack);
        free(pTmp);
  }
while(lstack->size>0);
    printf("栈销毁成功\n");
}